<?php

// register our sidebar for widgets
if ( function_exists('register_sidebar') )
{
	register_sidebar(array('before_widget' => '<div class="right">','after_widget' => '</div></div>','before_title' => '<div class="rightTitle">','after_title' => '</div><div class="rightWidget">',));
}

function print_post( $meta=false )
{
?>
			<div <?php post_class() ?> id="post-<?php the_ID(); ?>">
				<div class="posttitle"><div class="postdate"><?php the_date(); ?></div><h2><a href="<?php the_permalink(); ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2></div>
				<?php the_content(); ?>
				<p class="postmetadata"><?php the_tags('tags: ', ', ', '<br />'); ?> posted in <?php the_category(', ') ?> | <?php edit_post_link('Edit', '', ' | '); ?>  <?php comments_popup_link('no comments &#187;', '1 comment &#187;', '% Comments &#187;'); ?></p>
                <?php if( $meta ) { print_meta(); } ?>
			</div>
<?php
}

function print_meta()
{
?>
				<p class="postmetadata alt">
					<small>
						<b>posted:</b> <?php the_time('l, F jS, Y') ?> @ <?php the_time() ?><br />
                        <b>categories:</b> <?php the_category(', ') ?><br />
                        <b>comments feed:</b> <?php post_comments_feed_link('RSS 2.0'); ?>
                    </small>
                </p>
                    
				<p class="postmetadata alt">

						<?php if (('open' == $post-> comment_status) && ('open' == $post->ping_status)) {
							// Both Comments and Pings are open ?>
							You can <a href="#respond">leave a response</a>, or <a href="<?php trackback_url(); ?>" rel="trackback">trackback</a> from your own site.

						<?php } elseif (!('open' == $post-> comment_status) && ('open' == $post->ping_status)) {
							// Only Pings are Open ?>
							Responses are currently closed, but you can <a href="<?php trackback_url(); ?> " rel="trackback">trackback</a> from your own site.

						<?php } elseif (('open' == $post-> comment_status) && !('open' == $post->ping_status)) {
							// Comments are open, Pings are not ?>
							You can skip to the end and leave a response. Pinging is currently not allowed.

						<?php } elseif (!('open' == $post-> comment_status) && !('open' == $post->ping_status)) {
							// Neither Comments, nor Pings are open ?>
							Both comments and pings are currently closed.

						<?php } edit_post_link('Edit this entry','','.'); ?>
				</p>
<?php
}

function print_page()
{
?>
			<div class="page" id="post-<?php the_ID(); ?>">
            	<div id="main"><div class="post">
					<!-- <p class="pagetitle"><?php the_title(); ?></p> -->
    	            <?php print_title( the_title('','',false) ); ?>
					<?php the_content(); ?>
					<?php wp_link_pages(array('before' => '<p><strong>Pages:</strong> ', 'after' => '</p>', 'next_or_number' => 'number')); ?>
                </div></div>
			</div>
<?php
}

function print_title( $title )
{
	echo '<div class="posttitle"><h2>'.$title.'</h2></div>';
}


// keep track of how many fotos exist
$NUM_FOTOS = 0;

// [foto url="local-url" colorcorrect="0-100"]

function foto_func($atts, $content)
{
	global $NUM_FOTOS;
	extract(shortcode_atts(array(
		'url' => '',
		'colorcorrect' => '0',
	), $atts));

	$output = "";
	if( $url )
	{
		$swf = get_bloginfo('stylesheet_directory')."/images/Foto.swf";
		$foto_blog_foto = implode( "/", explode( "/", $_SERVER['SCRIPT_FILENAME'], -1 ) )."/wp-content/themes/fotoblog/images/Foto.swf";
		//$foto_blog_foto = "foo";
		if( file_exists( $foto_blog_foto ) )
		{
$output =<<<END
	<div class="foto" id="foto$NUM_FOTOS">&nbsp;</div>
    <script type="text/javascript">
		// <![CDATA[
			var so = new SWFObject("$swf", "foto$NUM_FOTOS", "600", "450", "9", "#FFFFFF");
			so.addParam("wmode", "transparent");
			so.addVariable("pic", "$url");
			so.addVariable("colorcorrect", "$colorcorrect" );
			so.write("foto$NUM_FOTOS");
		// ]]>
	</script>
END;
		} else {
			$output = "<img class='foto' src='$url' alt='unable to find ".$foto_blog_foto."' width='600' height='450' />";
        }
		$NUM_FOTOS++;
	}
	return $output;
}

add_shortcode('foto', 'foto_func');


?>